#include <fstream>
#include <iostream>
#include <vector>

void writeBinaryFile(const std::string& filename, const std::vector<int>& data) {
    std::ofstream outfile(filename, std::ios::binary);
    if (outfile.is_open()) {
        outfile.write(reinterpret_cast<const char*>(data.data()), data.size() * sizeof(int));
        outfile.close();
    }
}

std::vector<int> readBinaryFile(const std::string& filename) {
    std::ifstream infile(filename, std::ios::binary);
    std::vector<int> data;
    int value;
    while (infile.read(reinterpret_cast<char*>(&value), sizeof(int))) {
        data.push_back(value);
    }
    infile.close();
    return data;
}

int main() {
    // Create some data to write
    std::vector<int> numbers = {1, 2, 3, 4, 5};

    // Write data to binary file
    std::string filename = "example.bin";
    writeBinaryFile(filename, numbers);

    // Read data from binary file
    std::vector<int> readNumbers = readBinaryFile(filename);

    // Display read data
    std::cout << "Data read from file:" << std::endl;
    for (int num : readNumbers) {
        std::cout << num << std::endl;
    }

    return 0;
}